package game;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ScoreList extends JPanel {

	/**
	 * @param args
	 */
	ArrayList<Player> players;
//	Player me;
	private ArrayList<JLabel> labels = new ArrayList<JLabel>();
	private ArrayList<Color> colors = new ArrayList<Color>();

	
	public ScoreList(ArrayList<Player> players) {
		super();
		this.setLocation(600,100);
		this.setMinimumSize(new Dimension(150, 0));
		this.setPreferredSize(new Dimension(150, 0));
		this.setLayout(new GridLayout(20, 20, 0, 0));
		this.setBackground(new Color(0, 0, 0));
		this.setVisible(true);
		this.players = players;
		
		colors.add(new Color(29, 34, 203));
		colors.add(new Color(203, 29, 29));
		colors.add(new Color(91, 23, 176));
		colors.add(new Color(25, 235, 202));
		colors.add(new Color(200, 235, 25));
		colors.add(new Color(233, 25, 235));
		draw();
	}
	public void draw() {
		for (int j = 0; j < players.size(); j++) {
				JLabel l = new JLabel(players.get(j).ToString());
				l.setForeground(colors.get(players.get(j).color - 1));
				l.setSize(50,200);
				this.add(l);
				labels.add(l);
		}	
	}	
	public void updateScoreOnScreen(Player p) {
		int playerno = players.indexOf(p);
		if(playerno >= labels.size()) {
			for(JLabel l : labels) {
				this.remove(l);
			}
			labels = new ArrayList<JLabel>();
			draw();
		}
		labels.get((playerno)).setText(players.get(playerno).ToString());
	}	
}